package main

import (
	"fmt"
	"strconv"
)

func main() {
	i := int32(97)
	ret := string(i) //字符串97 ===  a
	fmt.Println(ret)
	fmt.Printf("%#v---%v \n", ret, ret)

	ret2 := fmt.Sprintf("%d", i)
	fmt.Printf("%#v---%v \n", ret2, ret2)

	//1.把字符串转换成数字类型
	str := "2147483649"
	ret3, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		fmt.Println("parseint failed,err:", err)
	}
	fmt.Printf("%T---%v \n", ret3, ret3)

	//2.第二种方法，字符串转数字
	retInt, _ := strconv.Atoi(str)
	fmt.Printf("%T---%v \n", retInt, retInt)

	//3.数字转字符串
	n := 97
	retStr := strconv.Itoa(n)
	fmt.Printf("%T---%#v \n", retStr, retStr)

	//4.从字符串中解析出布尔值
	boolStr := "true"
	boolValue, _ := strconv.ParseBool(boolStr)
	fmt.Printf("%T---%#v \n", boolValue, boolValue)

	//5.从字符串中解析出浮点数
	floatStr := "1.234"
	floatValue, _ := strconv.ParseFloat(floatStr, 64)
	fmt.Printf("%T---%#v \n", floatValue, floatValue)

	//第三位代表str中数值位数，不能溢出
	var str1 string = "1234"
	var n1 int64
	n1, _ = strconv.ParseInt(str1, 10, 8)
	numInt := int(n1)
	numUint := uint(n1)
	numInt32 := int32(n1)
	fmt.Println(numInt, numUint, numInt32)
}
